package de.fhkoeln.avs.parallelbreadthfirstsearch.infinitegraph;

import java.util.HashMap;

import com.infinitegraph.ConfigurationException;
import com.infinitegraph.GraphDatabase;
import com.infinitegraph.GraphFactory;
import com.infinitegraph.StorageException;
import com.infinitegraph.Transaction;
import de.fhkoeln.avs.parallelbreadthfirstsearch.infinitegraph.mockup.RAMPersistentVertex;

public class DatabaseConnection {

	private static GraphDatabase database;
	
	private static Transaction tx;
	
	private static HashMap<String, RAMPersistentVertex> vertex = new HashMap<String, RAMPersistentVertex>();
	
	public static GraphDatabase getConnection() throws StorageException, ConfigurationException{
		if (database == null) {
			String graphDbName = "AVSGraph"; //"Test";
			String propertiesFileName = "AVSGraph.properties"; //"Test.properties";

			database = GraphFactory.open(graphDbName, propertiesFileName);
		}
		return database;
	}
	
	public static Transaction getTransaction(){
		if(tx ==null){
			database.beginTransaction();
		}
		return tx;
	}
	
	public static RAMPersistentVertex getVertex(String vertexName) {
		return vertex.get(vertexName);
	}
	
	public static void commitTransaction(Object thread){
		
	}
}
